package com.example.ovulationperiodtracker.Allactivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.example.ovulationperiodtracker.databinding.ActivityWebBinding;
import com.gyf.immersionbar.ImmersionBar;
import com.just.agentweb.AgentWeb;
import com.necer.base.BaseActivity;

public class WebActivity extends BaseActivity<ActivityWebBinding> {


    public static void startActivity(Context context, String title, String url) {
        Intent intent = new Intent(context, WebActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("url", url);
        context.startActivity(intent);
    }

    private String title;
    private String url;

    private AgentWeb agentWeb;


    @Override
    protected ActivityWebBinding createBinding(LayoutInflater inflater) {
        return ActivityWebBinding.inflate(inflater);
    }

    @Override
    protected void onCreated(Bundle savedInstanceState) {
      //  ImmersionBar.with(this).statusBarDarkFont(true).navigationBarColor(com.necer.base.R.color.white).init();

        title = getIntent().getStringExtra("title");
        url = getIntent().getStringExtra("url");

        binding.navigation.setTitle(title);


        agentWeb = AgentWeb.with(this)
                .setAgentWebParent(binding.llWeb, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .setMainFrameErrorView(com.just.agentweb.R.layout.agentweb_error_page, -1)
                .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
                .interceptUnkownUrl() //拦截找不到相关页面的Scheme
                .createAgentWeb()
                .ready()
                .go(url);

    }

    @Override
    protected void onPause() {
        agentWeb.getWebLifeCycle().onPause();
        super.onPause();

    }

    @Override
    protected void onResume() {
        agentWeb.getWebLifeCycle().onResume();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        agentWeb.getWebLifeCycle().onDestroy();
    }
}
